package com.wing.file.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.file.model.response.FileVO;
import com.wing.web.utils.JwtUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: aaa
 * @Project: szgc_new
 * @Package: com.wing.file.service.impl.PicService
 * @Date: 2025/05/27 15:31
 * @Author: heZhou
 * @Version: 1.0
 */
@Service
public class PicServiceImpl extends ServiceImpl<ResProductDrawPicDao,ResProductDrawPic> implements PicService{
    /**
     * 添加信息
     * @param resProductDrawPics 图片信息
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addInfo(List<FileVO> resProductDrawPics) {
        //先删除
        this.baseMapper.delete(null);
        //添加
        List<ResProductDrawPic> resProductDrawPic=new ArrayList<>();
        if (CollectionUtil.isNotEmpty(resProductDrawPics)) {
            for (FileVO productDrawPic : resProductDrawPics) {
                ResProductDrawPic productDetail=new ResProductDrawPic();
                productDetail.setFileUrl(productDrawPic.getUrl());
                productDetail.setName(productDrawPic.getFileName());
                productDetail.setCreateTime(productDrawPic.getModifiedTime());
                productDetail.setCreator(JwtUtils.getLoginUserId());
                productDetail.setCreatorName(JwtUtils.getLoginUsername());
                resProductDrawPic.add(productDetail);
            }
        }
        boolean saved = this.saveBatch(resProductDrawPic);
        if (saved) {
            return true;
        }
        return false;
    }

}
